<?php

/**
 * Created by PhpStorm.
 * User: WhiteBlue
 * Date: 15/3/2
 * Time: 下午3:36
 */
class router
{
    private $route;
    private $controller;
    private $action;
    private $params;
    private $method;

    public function __construct()
    {
        $path = array_keys($_GET);
        if (!isset($path[0])) {
            if (!empty($default_controller))
                $path[0] = $default_controller;
            else {
                $path[0] = "index";
            }
        }
        $route = htmlspecialchars($path[0]);
        $this->route = $route;

        $routeParts = split("/", $route);
        $this->controller = $routeParts[0] . 'Controller';

        $this->action = empty($routeParts[1]) ? "index" : $routeParts[1];

        array_shift($routeParts);
        array_shift($routeParts);

        $this->method = $_SERVER['REQUEST_METHOD'];
        if($this->method=='GET'){
            $this->params = $routeParts;
        }else{
            $this->params=$_POST;
        }
    }

    public function getAction()
    {
        return $this->action;
    }

    public function getController()
    {
        return $this->controller;
    }

    public function getParams()
    {
        return $this->params;
    }

    public function getMethod()
    {
        return $this->method;
    }


}